
package combat.dudes.client.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import combat.dudes.DudesFunctions;
import combat.dudes.client.ClientApp;
import combat.dudes.client.gui.threads.shell.GUIShell;


/**
 * The theme of the GUI is defined here. "LaF" stands for "Look and Feel" (the looks of the GUI).
 * The standard theme is set to "nimbus", but it is modified in a few aspects. Review the code of this file to find out which aspects.
 * @author Laurens Andriessen
 */
public class ClientGUITheme extends GUIShell {

	public static GUILaF currentTheme = null;

	public static final String guiLookAndFeel = "Nimbus"; // The "nimbus" theme

	public static Font guiFont = new Font("Segoe UI", Font.PLAIN, 13); // The standard GUI font
	public static Font guiFontFixed = new Font("Lucida Console", Font.PLAIN, 12); // Fixed font

	public static Color guiPanelBg = new Color(214, 217, 223); // The background color of all panels
	public static Color guiMainMapSea = new Color(120, 178, 236); // The color of the sea
	public static Color guiMainMapLand = new Color(153, 179, 159); // The color of land (deprecated)

	public enum GUILaF {
		LIGHT, NORMAL, DARK
	};

	/**
	 * Set the look and feel of the client GUI.
	 * @param accent Either LIGHT, NORMAL or DARK
	 */
	public static void setGUILookAndFeel(GUILaF accent) {
		// UIManager.put("DesktopPane[Enabled].backgroundPainter", new Painter()); // Buggy!!! Doesn't work yet.
		// UIManager.put("text", new Color(255, 255, 255)); // All text to white
		UIManager.put("defaultFont", new Font("Segoe UI", Font.PLAIN, 13)); // Set the default font
		UIManager.put("nimbusDisabledText", new Color(40, 40, 40)); // Set the default unfocussed font

		currentTheme = accent;

		switch(accent) {
			case LIGHT:
				UIManager.put("nimbusBase", new Color(0x33628C).brighter());
				UIManager.put("nimbusBlueGrey", new Color(0xA9b0bE).brighter());
				UIManager.put("control", new Color(0xD6D9DF).brighter());

				guiPanelBg = new Color(214, 217, 223).brighter();
				guiMainMapSea = guiMainMapSea.brighter();
				guiMainMapLand = guiMainMapLand.brighter();
				break;
			case DARK:
				UIManager.put("nimbusBase", new Color(0x33628C).darker());
				UIManager.put("nimbusBlueGrey", new Color(0xA9b0bE).darker());
				UIManager.put("control", new Color(0xD6D9DF).darker());

				guiPanelBg = new Color(214, 217, 223);
				guiMainMapSea = guiMainMapSea.darker();
				guiMainMapLand = guiMainMapLand.darker();
				break;
			case NORMAL:
			default:
				UIManager.put("nimbusBase", new Color(0x33628C));
				UIManager.put("nimbusBlueGrey", new Color(0xA9b0bE));
				UIManager.put("control", new Color(0xD6D9DF));

				guiPanelBg = new Color(153, 179, 159);
				guiMainMapSea = new Color(167, 178, 189);
				guiMainMapLand = new Color(153, 179, 159);
				break;
		}

		// Set the look and feel within the client's GUI
		try {
			for(LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
				if(guiLookAndFeel.equals(info.getName())) { // get nimbus' LaF
					UIManager.setLookAndFeel(info.getClassName()); // set nimbus' LaF
					break;
				}
			}
		} catch(Exception e) {
			ClientApp.onError("Couldn't set Nimbus theme on GUI.", e, false);
		}

	}

	/**
	 * The background of the client GUI (currently: Ministry of Defense logo)
	 * @author Laurens Andriessen
	 */
	public static class Background {

		public static final Boolean showBgImage = true;

		public static final Color gradientLight = new Color(200, 200, 200); // light grey (used if the background image can't be found)
		public static final Color gradientDark = new Color(100, 100, 100); // dark grey (used if the background image can't be found)

		// Main window ('desktop') background, placed in combat.dudes.client.gui.images
		// Source: http://www.psdgraphics.com/backgrounds/world-map-background/
		public static final String bgImageSrc = "bg.png";
		// public static final String bgImageSrc = "worldmap-1920px.jpg";
		public static final Image bgImage = DudesFunctions.File.getImage(bgImageSrc);

		// Background for the login panel
		public static final Image bgLogIn = DudesFunctions.File.getImage("background-login.jpg");

	}

	// Add a tab to a JTabbedPane, with an icon and the right properties set
	public static void addTab(JTabbedPane tabContainer, Component content, String title, String icon) {
		// http://stackoverflow.com/questions/1782224/jtabbedpane-icon-on-left-side-of-tabs

		tabContainer.addTab("", content);

		JLabel lbl = new JLabel(title);
		lbl.setIcon(new ImageIcon(DudesFunctions.File.getIcon(icon)));

		// Add some spacing between text and icon, and position text to the RHS.
		lbl.setFont(new Font("Sans Serif", Font.PLAIN, 12));
		lbl.setIconTextGap(6);
		lbl.setHorizontalTextPosition(SwingConstants.RIGHT);

		// Assign bespoke tab component for first tab.
		tabContainer.setTabComponentAt(tabContainer.getTabCount() - 1, lbl);

	}
}
